//
//  firstPageSecondSecctionCell_Ht.m
//  WZLProduct
//
//  Created by dllo on 16/3/19.
//  Copyright © 2016年 HaiTeng. All rights reserved.
//

#import "firstPageSecondSecctionCell_Ht.h"
#import <UIButton+WebCache.h>
@interface firstPageSecondSecctionCell_Ht ()
@property (nonatomic, strong) UIImageView *backImg; /**< 渲染图 */
@end

@implementation firstPageSecondSecctionCell_Ht

- (void)setModel:(WHTFirstPageTripModel *)model{
    if (model) {
        [self.cover_image sd_setImageWithURL:[NSURL URLWithString:model.cover_image] placeholderImage:[UIImage imageNamed:@"PlaceH.older_W_Ht"]];
        self.name.text = model.name;
        self.first_dayAndDay_CountAndView_Count.text = [NSString stringWithFormat:@"%@  %@ 天  %@ 浏览",model.first_day,model.day_count,model.view_count];
        self.popular_place_str.text = model.popular_place_str;
        [self.avatar_s sd_setBackgroundImageWithURL:[NSURL URLWithString:model.avatar_m] forState:UIControlStateNormal];
        self.userName.text = [NSString stringWithFormat:@" by %@",model.userName];
    }
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.contentView.layer.masksToBounds = YES;
        self.contentView.layer.cornerRadius = 4;
        self.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"PlaceHolder_W_Ht"]];
        
        self.cover_image = [[UIImageView alloc] init];
        [self.contentView addSubview:self.cover_image];
        
        self.backImg = [[UIImageView alloc] init];
        [self.contentView addSubview:self.backImg];
        self.backImg.alpha = 0.15;
        self.backImg.image = [UIImage imageNamed:@"dest_around_shadow"];
        
        self.name = [[UILabel alloc] init];
        [self.contentView addSubview:self.name];
        
        self.first_dayAndDay_CountAndView_Count = [[UILabel alloc] init];
        [self.contentView addSubview:self.first_dayAndDay_CountAndView_Count];
        
        self.popular_place_str = [[UILabel alloc] init];
        [self.contentView addSubview:self.popular_place_str];
        
        self.avatar_s = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.contentView addSubview:self.avatar_s];
        
        self.userName = [[UILabel alloc] init];
        [self.contentView addSubview:self.userName];
        
        
        self.cover_image.image = [UIImage imageNamed:@"TestPicture_HT.jpg"];
        self.name.text = @"XXXXXXXXXXXXXX";
        self.name.textColor = [UIColor whiteColor];
        [self.name setFont:[UIFont fontWithName:@"Helvetica-Bold" size:20]];
        self.first_dayAndDay_CountAndView_Count.textColor = [UIColor whiteColor];
        self.first_dayAndDay_CountAndView_Count.text = @"2015.08.12  15 天  7103 浏览";
        [self.first_dayAndDay_CountAndView_Count setFont:[UIFont fontWithName:@"Helvetica-Bold" size:9]];
        self.popular_place_str.text = @"中国 阿富汗 马来西亚";
        self.popular_place_str.textColor = [UIColor whiteColor];
        self.popular_place_str.font = [UIFont systemFontOfSize:9];
        
        self.avatar_s.backgroundColor = [UIColor colorWithRed:0.91 green:0.87 blue:0.78 alpha:1];
        self.avatar_s.layer.masksToBounds = YES;
        self.avatar_s.layer.cornerRadius = self.contentView.height * 0.1;
        
        self.userName.textColor = [UIColor whiteColor];
        self.userName.font = FONT10;
        self.userName.text = @" By 海腾";
//        self.userName.backgroundColor = [UIColor orangeColor];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    [self.cover_image mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.and.right.equalTo(self.contentView);
    }];
    
      self.backImg.frame = self.cover_image.frame;
    
    [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.contentView).with.offset(10);
        make.height.equalTo(self.contentView).multipliedBy(0.2);
    }];
    
    [self.first_dayAndDay_CountAndView_Count mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.name.mas_bottom);
        make.left.equalTo(self.name).with.offset(10);
        make.size.equalTo(self.name).multipliedBy(0.5);
    }];
    
    [self.popular_place_str mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.first_dayAndDay_CountAndView_Count.mas_bottom);
        make.left.equalTo(self.first_dayAndDay_CountAndView_Count);
        make.size.equalTo(self.first_dayAndDay_CountAndView_Count);
    }];
    
    [self.avatar_s mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.name);
        make.bottom.equalTo(self.contentView).with.offset(-10);
        make.size.equalTo(self.contentView.mas_height).multipliedBy(0.2);
    }];
    
    [self.userName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.avatar_s.mas_right);
        make.right.equalTo(self.contentView);
        make.centerY.equalTo(self.avatar_s.mas_centerY);
        make.height.equalTo(self.avatar_s.mas_height).multipliedBy(0.5);
    }];
    
  
}

@end
